from cmath import log
from fastapi import APIRouter, Request
import requests
import json


baiduRouter = APIRouter(prefix="/baidu", tags=['百度'])

'逆地理信息查询'


@baiduRouter.get("/BaiDuGeocode", summary="百度地理信息编码")
async def get_geocode(request: Request, address: str = "北京市朝阳区阜通东大街6号"):
    content = []
    for ads in address.split(','):
        params = {
            "ak": 'uL6HBmSCu30DdvjGewpYz8ULGxcV2Hl7',
            "address": ads,
            "output": 'json'
        }
        try:
            results = requests.get(
                "https://api.map.baidu.com/geocoding/v3/", params=params, verify=True)
            print(results)
            content.append(results.text)
        except:
            return "err"
    return {
        "content": content
    }
